package com.gxa.order.controller;

import com.gxa.common.commons.R;


import com.gxa.common.utils.UploadController;
import com.gxa.order.pojo.*;
import com.gxa.order.service.FinancialMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.HashMap;

@RestController
@RequestMapping("/fuwu")
public class FinancialMsgController {
    @Autowired
    private FinancialMsgService financialMsgService;

    private UploadController uploadUtil = new UploadController();


//    订单查询财务-收付款详情
    @GetMapping("/findshoufukuan")
    public R findshoufukuan(String pay_id){
        R r = financialMsgService.findshoufukuan(pay_id);
        return r;
    }
    //    订单查询财务-查询所有的收付款信息
    @GetMapping("/findshoufukuanAll")
    public R findshoufukuanAll(Integer currentPage, Integer pageSize,String clean_order_number){
        R r = financialMsgService.findshoufukuanAll(currentPage, pageSize,clean_order_number);
        return r;
    }


    //    订单查询财务-添加收付款
    @GetMapping("/addshoufukuan")
    public R addshoufukuan (Mpay mpay, Mmoney mmoney){
        mpay.setCreateDate(new Timestamp(System.currentTimeMillis()));
        mmoney.setCreateDate(new Timestamp(System.currentTimeMillis()));
        if(mmoney.getMoneyfile()!=null){
            HashMap upload =(HashMap) uploadUtil.upload(mmoney.getMoneyfile());
            String url = upload.get("url").toString();
            mmoney.setMfile(url);
            System.out.println("-------"+url);

        }
        R r = financialMsgService.addshoufukuan(mpay, mmoney);
        return r;
    }


    //    订单查询财务-编辑收付款
    @GetMapping("/updateshoufukuan")
    public R updateshoufukuan (Mpay mpay, Mmoney mmoney){
        mpay.setCreateDate(new Timestamp(System.currentTimeMillis()));
        mmoney.setCreateDate(new Timestamp(System.currentTimeMillis()));
        if(mmoney.getMoneyfile()!=null){
            HashMap upload =(HashMap) uploadUtil.upload(mmoney.getMoneyfile());
            String url = upload.get("url").toString();
            mmoney.setMfile(url);
            System.out.println("-------"+url);
        }
        R r = financialMsgService.updateshoufukuan(mpay, mmoney);
        return r;
    }


    //    订单查询财务-添加合同
    @GetMapping("/addhetong")
    public R addhetong (Mpay mpay, Mmoney mmoney, Mpact mpact){
        mpay.setCreateDate(new Timestamp(System.currentTimeMillis()));
        mmoney.setCreateDate(new Timestamp(System.currentTimeMillis()));
        mpact.setCreateDate(new Timestamp(System.currentTimeMillis()));
        if(mmoney.getMoneyfile()!=null){
            HashMap upload =(HashMap) uploadUtil.upload(mmoney.getMoneyfile());
            String url = upload.get("url").toString();
            mmoney.setMfile(url);
            System.out.println("-------"+url);

        }
        if(mpact.getPfile()!=null){
            HashMap upload =(HashMap) uploadUtil.upload(mpact.getPfile());
            String url = upload.get("url").toString();
            mpact.setPactFile(url);
            System.out.println("-------"+url);

        }
        R r = financialMsgService.addhetong(mpay, mmoney, mpact);

        return r;
    }

    //    订单查询财务-编辑合同
    @GetMapping("/updatehetong")
    public R updatehetong (Mpay mpay, Mmoney mmoney, Mpact mpact){
        mpay.setCreateDate(new Timestamp(System.currentTimeMillis()));
        mmoney.setCreateDate(new Timestamp(System.currentTimeMillis()));
        mpact.setCreateDate(new Timestamp(System.currentTimeMillis()));
        if(mmoney.getMoneyfile()!=null){
            HashMap upload =(HashMap) uploadUtil.upload(mmoney.getMoneyfile());
            String url = upload.get("url").toString();
            mmoney.setMfile(url);
            System.out.println("-------"+url);

        }
        if(mpact.getPfile()!=null){
            HashMap upload =(HashMap) uploadUtil.upload(mpact.getPfile());
            String url = upload.get("url").toString();
            mpact.setPactFile(url);
            System.out.println("-------"+url);

        }
        R r = financialMsgService.updatehetong(mpay, mmoney, mpact);

        return r;
    }

    //    订单查询财务-查询所有合同信息
    @PostMapping ("/findhetongAll")
    public R findhetongAll (Integer currentPage, Integer pageSize,String clean_order_number){
        System.out.println("订单号======="+clean_order_number);
        R r = financialMsgService.findhetongAll(currentPage, pageSize,clean_order_number);

        return r;
    }

    //    订单查询财务-合同详情
    @PostMapping ("/findhetong")
    public R findhetong (String pact_id,String pay_id){
        System.out.println("pact======"+pact_id);
        System.out.println("pay======"+pay_id);
        R r = financialMsgService.findhetong(pact_id, pay_id);

        return r;
    }

    //    订单查询财务-查询项目跟进
    @PostMapping ("/findgenjin")
    public R findgenjin(Integer currentPage,Integer pageSize){
        R r = financialMsgService.findgenjin(currentPage, pageSize);

        return r;
    }

    //    订单查询财务-添加项目跟进
    @PostMapping ("/addgenjin")
    public R addgenjin (GenJin genJin){
        genJin.setCreateDate(new Timestamp(System.currentTimeMillis()));
        if(genJin.getZiliaofile()!=null){
            HashMap upload =(HashMap) uploadUtil.upload(genJin.getZiliaofile());
            String url = upload.get("url").toString();
            genJin.setZiliao(url);
            System.out.println("-------"+url);

        }
        R r = financialMsgService.addgenjin(genJin);

        return r;
    }

    //    订单查询财务-编辑项目跟进
    @PostMapping ("/updategenjin")
    public R updategenjin  (GenJin genJin){
        genJin.setCreateDate(new Timestamp(System.currentTimeMillis()));
        if(genJin.getZiliaofile()!=null){
            HashMap upload =(HashMap) uploadUtil.upload(genJin.getZiliaofile());
            String url = upload.get("url").toString();
            genJin.setZiliao(url);
            System.out.println("-------"+url);

        }
        R r = financialMsgService.updategenjin(genJin);

        return r;
    }

    //    订单查询财务-查询项目提醒
    @PostMapping ("/findtixin")
    public R findtixin(Integer currentPage,Integer pageSize){
        R r = financialMsgService.findtixin(currentPage, pageSize);

        return r;
    }


    //    订单查询财务-添加项目提醒
    @PostMapping ("/addtixin")
    public R addtixin(TiXin tiXin){
        tiXin.setCreateDate(new Timestamp(System.currentTimeMillis()));
        R r = financialMsgService.addtixin(tiXin);

        return r;
    }

    //    订单查询财务-编辑项目提醒
    @PostMapping ("/updatetixin")
    public R updatetixin (TiXin tiXin){
        tiXin.setCreateDate(new Timestamp(System.currentTimeMillis()));
        R r = financialMsgService.updatetixin(tiXin);
        return r;
    }
}
